package momo.multitree.simulation;

import momo.multitree.structure.Graph;
import momo.multitree.structure.Tree;

public class LatCostOptTree extends SimulatedAnnealing{

	public LatCostOptTree(Graph g, int maxIteration, int maxTrial, double temperature, double factor) {
		super(g, maxIteration, maxTrial, temperature, factor);
	}

	public LatCostOptTree(Graph g) {
		super(g);
	}
	
	public double score(Tree t) {
		double latT, costT, stabT;
		double lat = t.compWeightedLatency();
		double cost = t.compCost(false);
		
		double bestLat = bestLatTree.compWeightedLatency();
		double worstLat = bestCostTree.compWeightedLatency() > bestStabTree.compWeightedLatency() ? bestCostTree.compWeightedLatency() :  bestStabTree.compWeightedLatency();
		
		double bestCost = bestCostTree.compCost(false);
		double worstCost = bestLatTree.compCost(false) > bestStabTree.compCost(false) ? bestLatTree.compCost(false) : bestStabTree.compCost(false);
		
		latT = ( lat - bestLat ) / ( worstLat - bestLat );
		if ( Double.isNaN(latT) || Double.isInfinite(latT) ) latT = 0;
		
		costT = ( cost - bestCost ) / ( worstCost - bestCost );
		if ( Double.isNaN(costT) || Double.isInfinite(costT) ) costT = 0;
		
		stabT = 0;
		
		double dist = Math.sqrt( Math.pow(latT, 2) + Math.pow(costT, 2) + Math.pow(stabT, 2) );
		return dist;
	}
	
}//end of class LatCostOptTree
